package IOPerations;

import Books.BooksList;

import java.util.Scanner;

public class DelOperations implements IOperations{
    //删除书籍
    @Override
    public void work(BooksList booksList) {
        System.out.println("删除书籍");
        System.out.println("请输入你想要删除的书籍");

        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int tmp = booksList.getVal();

        for (int i = 0; i < tmp; i++) {
            if (booksList.getBook(i).getName().equals(name)){
                if(i == tmp - 1){
                    booksList.setVal(tmp - 1);
                    System.out.println("删除成功");
                    return;
                }else{
                    booksList.setBooks(booksList.getBook(i+1),i);
                    System.out.println("删除成功");
                    return;
                }
            }
        }
        System.out.println("没有找到你要删除的这本书");
    }
}
